package top.hcode.hoj;

import cn.hutool.core.util.RandomUtil;
import top.hcode.hoj.common.LazyDao;

import java.util.HashSet;
import java.util.Set;

/**
 * 生成指定数量的用户名，并检查是否存在
 * @author orangej
 * @since 2025/5/21
 */
public class GenUsernameApp extends BaseDbApp {


    String genUsername() {
        return RandomUtil.randomString("abcdefghijklmnopqrstuvwxyz", 4) +
               RandomUtil.randomNumbers(4);
    }
    
    public static void main(String[] args) {
        LazyDao dao = buildLazyDao();
        GenUsernameApp app = new GenUsernameApp();
        
        int max = 11;
        Set<String> set = new HashSet<>();
        while (set.size() < max) {
            String username = app.genUsername();
            if (set.contains(username)) continue;
            int exists = dao.fetchInt("select count(1) from org_user where username = ?", username);
            if (exists == 0) {
                set.add(username);
            }
        }

        for (String username : set) {
            System.out.println(username);
        }
    }
}
